<?php

/**
 * author  : TrongNV
 * name    : Model_Comment
 * version : 1.0
 */
class Comment {

    /**
     * Parent instance
     * @var object
     */
    private $_modelParent = null;

    /**
     *
     * @var type
     */
    protected static $_instance = null;

    /**
     * Constructor of class
     * we don't permit an explicit call of the constructor! (like $v = new Singleton())
     */
    protected function __construct() {
        //Init parent model
        $this->_modelParent = My_Business_Storage_Comment::getInstance();
    }

    /**
     * Get singletom instance
     * @return Comment
     */
    public final static function getInstance() {
        //Check instance
        if (is_null(self::$_instance)) {
            self::$_instance = new self();
        }

        //Return instance
        return self::$_instance;
    }

    /**
     * Insert comment
     * @param int $p_intUserID
     * @param array $p_arrData
     * @return int $intResult : last inserted ID
     * @todo wrong params for cache
     */
    public function insert($p_intUserID, $p_arrData) {
        if (empty($p_arrData)) {
            return false;
        }

        //Insert Data
        $intResult = $this->_modelParent->insert($p_intUserID, $p_arrData);
        return $intResult;
    }
    
    
    /**
     * Delete comment 
     * @param int $p_intUserID, int $p_intCommentID
     * @return int $result : 1 success
     */
    public function delete($p_intUserID, $p_intCommentID) {
        //Delete Data
        $intResult = $this->_modelParent->delete($p_intUserID, $p_intCommentID);

        //Return data
        return $intResult;
    }

    /**
     * Get list comment by condition
     * @param array $p_arrCondition
     * @param int   $p_intPage
     * @param int   $p_intLimit
     * @return array $result
     */
    public function getListComment() {
        $arrResult = $this->_modelParent->getListComment();
        return $arrResult;
    }

    /**
     * Get list comment limit by condition
     * @param array $p_arrCondition
     * @param int   $p_intPage
     * @param int   $p_intLimit
     * @return array $result
     */
    public function getListLimit($p_arrCondition=array(), $p_intPage=1, $p_intLimit=15) {
        $result = array();

        //Check param
        if (!is_array($p_arrCondition) || $p_intPage < 1 || $p_intLimit < 1) {
            return $result;
        }

        //Get data
        $result = $this->_modelParent->getListLimit($p_arrCondition, $p_intPage, $p_intLimit);

        //Return
        return $result;
    }
}
